package com.atmilan.quartz.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atmilan.quartz.constant.Constants;
import com.atmilan.quartz.mapper.SystemAttachmentMapper;
import com.atmilan.quartz.model.entity.crmeb.SystemAttachment;
import com.atmilan.quartz.service.IAsyncService;
import com.atmilan.quartz.service.ISystemAttachmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
* @author Mr.Zhang
* @Description SystemAttachmentServiceImpl 接口实现
* @since 2020-05-08
*/
@Service
public class SystemAttachmentServiceImpl extends ServiceImpl<SystemAttachmentMapper, SystemAttachment> implements ISystemAttachmentService {
    @Autowired
    private IAsyncService asyncService;

    /**
     * 清除 cdn url， 在保存数据的时候使用
     * @param path String 文件路径
     * @return String
     */
    @Override
    public String clearPrefix(String path) {
        if (StringUtils.isBlank(path)) {
            return path;
        }
        Constants.CND_URL = asyncService.getCurrentBaseUrl();
        if (path.contains(getCdnUrl() + "/")) {
            return path.replace(getCdnUrl() + "/", "");
        }

        return path;
    }

    /**
     * 获取cdn url
     * @return String
     */
    private String getCdnUrl() {
        return asyncService.getCurrentBaseUrl();
    }

}
